import {get, post} from "../../utils/req";
import {alert} from "../../components/common/alert";

export async function list() {
    try {
        return await get('/private/course/list') || [];
    } catch (e) {
        alert(`获取课程信息失败：${e}`, 'error');
        return [];
    }
}

export async function valid() {
    try {
        return await get('/private/course/valid') || [];
    } catch (e) {
        alert(`获取课程信息失败：${e}`, 'error');
        return [];
    }
}

export async function save(course) {
    try {
        return await post('/private/course/save', course);
    } catch (e) {
        alert(`保存课程信息失败：${e}`, 'error');
        return 0;
    }
}

export async function visible(id, visible) {
    try {
        await get(`/private/course/visible?id=${id}&visible=${visible}`);
        return true;
    } catch (e) {
        alert(`修改课程状态失败：${e}`, 'error');
        return false;
    }
}
